const { addAdmin } = require('../service/addAdmin.service');

class AddAdmin {
  async addAdmin(ctx, next) {
    const { name, password } = ctx.request.body;

    // 判断用户名和密码是否传进来
    if (!name || !password) {
      const error = new Error('1000 [addAdmin.controller]');
      return ctx.app.emit('error', error, ctx);
    }

    const result = await addAdmin(name, password);
    console.log('[addAdmin.controller]新增管理员的操作------', result);

    ctx.body = {
      ret: 0,
      res: 'ok'
    }
  }
}

module.exports = new AddAdmin();